import { coreRoutes, fallbackNotFoundRoute } from "./core.js";

import { mergeRouteModules } from "../utils/merge-route-modules";
import { traverseTreeValues } from "../utils/tree";
import { DEFAULT_HOME_PATH } from "@/config.js";

const dynamicRouteFiles = import.meta.glob("./modules/**/*.js", {
  eager: true
});
/** 动态路由 */
const dynamicRoutes = mergeRouteModules(dynamicRouteFiles);
/** 静态路由 */
const staticRoutes = [
  {
    path: DEFAULT_HOME_PATH,
    name: "Home",
    component: () => import("@/pages/home/index.vue"),
    meta: {
      title: "首页",
      icon: "home",
      order: 1
    }
  }
];
//  外部路由 不需要layout 暂时不知道有什么用
const externalRoutes = [];

/** 路由列表，由基本路由、外部路由和404兜底路由组成
 *  无需走权限验证（会一直显示在菜单中） */
const routes = [...coreRoutes, ...externalRoutes, fallbackNotFoundRoute];

/** 基本路由列表，这些路由不需要进入权限拦截 */
const coreRouteNames = traverseTreeValues(coreRoutes, (route) => route.name);

/** 有权限校验的路由列表，包含动态路由和静态路由 */
const accessRoutes = [...dynamicRoutes, ...staticRoutes];
export { accessRoutes, coreRouteNames, routes };
